package cn.edu.scau.dormitory_management_system.service.impl;

import cn.edu.scau.dormitory_management_system.dao.RegisterDao;
import cn.edu.scau.dormitory_management_system.entity.RegisterEntity;
import cn.edu.scau.dormitory_management_system.service.RegisterService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;



@Service("registerService")
public class RegisterServiceImpl extends ServiceImpl<RegisterDao, RegisterEntity> implements RegisterService {


    @Override
    public boolean insertRegister(RegisterEntity registerEntity) {
        return this.baseMapper.insert(registerEntity) > 0;
    }

    @Override
    public boolean deleteRegister(RegisterEntity registerEntity) {
        return this.baseMapper.deleteById(registerEntity) > 0;
    }

    @Override
    public boolean updateRegister(RegisterEntity registerEntity) {
        return this.baseMapper.updateById(registerEntity) > 0;
    }

    @Override
    public List<RegisterEntity> findRegisterByTel(String tel) {
        return this.baseMapper.selectList(
                new QueryWrapper<RegisterEntity>().like("tel", tel)
        );
    }

    @Override
    public List<RegisterEntity> findRegisterByType(String type) {
        return this.baseMapper.selectList(
                new QueryWrapper<RegisterEntity>().eq("type", type)
        );
    }

    @Override
    public List<RegisterEntity> findRegisterByReason(String reason) {
        return this.baseMapper.selectList(
                new QueryWrapper<RegisterEntity>().eq("reason", reason)
        );
    }

    @Override
    public List<RegisterEntity> findRegisterBetweenTime(Date dateAfter, Date dateBefore) {
        return this.baseMapper.selectList(
                new QueryWrapper<RegisterEntity>().between("time", dateAfter, dateBefore)
        );
    }


}